package com.tianji.learning.listener;

import cn.hutool.core.util.ObjectUtil;
import com.tianji.api.dto.remark.LikedTimesDTO;
import com.tianji.learning.domain.po.InteractionReply;
import com.tianji.learning.domain.po.LearningRecord;
import com.tianji.learning.service.IInteractionReplyService;
import com.tianji.learning.service.ILearningRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import static com.tianji.common.constants.MqConstants.Exchange.LIKE_RECORD_EXCHANGE;
import static com.tianji.common.constants.MqConstants.Key.QA_LIKED_TIMES_KEY;
import static com.tianji.common.constants.MqConstants.Queue.QA_LIKED_TIMES_QUEUE;


@Slf4j
@Component
@RequiredArgsConstructor
public class LikeTimesChangeListener {
    private final IInteractionReplyService replyService;

    /**
     * 监听回复点赞次数变更消息，处理点赞次数变更
     * @param likedTimesMsg
     */
/*    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = QA_LIKED_TIMES_QUEUE, durable = "true"),
            exchange = @Exchange(name = LIKE_RECORD_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = QA_LIKED_TIMES_KEY
    ))
    public void likesTimesChangeMsq(LikedTimesDTO likedTimesMsg){
        // 消息健壮性判断
        if (ObjectUtil.isEmpty(likedTimesMsg) || ObjectUtil.isEmpty(likedTimesMsg.getBizId()) || ObjectUtil.isEmpty(likedTimesMsg.getLikedTimes())){
            log.error("点赞次数变更消息格式异常，消息{}",likedTimesMsg);
        }

        // 更新回复表对应的点赞次数
        log.info("更新回复表点赞次数，回复id：{}，点赞次数：{}",likedTimesMsg.getBizId(), likedTimesMsg.getLikedTimes());
        replyService.lambdaUpdate().eq(InteractionReply::getId, likedTimesMsg.getBizId())
                .set(InteractionReply::getLikedTimes, likedTimesMsg.getLikedTimes())
                .update();

    }*/
}
